#include <sds/sfile.h>
#include <sds/sdataset.h>
#include <sds/sdataview.h>

#include <cstdlib>

using namespace sds;
using namespace std;

int main(int argc, const char* argv[]) {
  SFile temfile(argv[1]);
  SDataView<unsigned char> tem = 
    temfile.getDataset(0).getDataView<unsigned char>();
  SFile reffile(argv[2]);
  SDataView<unsigned char> ref = 
    reffile.getDataset(0).getDataView<unsigned char>();

  vector<long> size = ref.getSize();

  for (int i = 0; i < size[0]; ++i) {
    for (int j = 0; j < size[1]; ++j) {
      if (ref[i][j] != 0) {
	if (ref[i][j] != tem[i][j]) {
	  ref[i][j] = 1;
	} else {
	  ref[i][j] = 2;
	}
      } 
    }
  }
  SFile output(argv[3], SFile::CREATE);
  SDataset out = output.createDataset("diff", UINT8, size);
  out.setDataView<unsigned char>(ref);
  
  return 0;
}
